<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Hello</title>
    <link rel="stylesheet" href="css/bootstrap.css">
</head>
<script src="js/jQuery.js"></script>
<script src="js/bootstrap.min.js"></script>
<body>
<div class="container">
    <table class="table table-bordered table-striped">
        <thead>
        <tr>
            <td colspan="7" class="text-center"><h1>空气质量监测信息库</h1></td>
        </tr>
        <tr class="text-lowercase">
            <td>序号</td>
            <td>区域</td>
            <td>监测时间</td>
            <td>PM10数据</td>
            <td>PM2.5数据</td>
            <td>监测站</td>
            <td>操作</td>
        </tr>
        </thead>
        <tr th:each="m:${pageUtil.allAirQuality}">
            <td th:text="${m.id}">1</td>
            <td th:text="${m.district.name}">2</td>
            <td th:text="${m.monitorTime}">3</td>
            <td th:text="${m.pm10}">4</td>
            <td th:text="${m.pm2_5}">5</td>
            <td th:text="${m.monitoringStation}">6</td>
            <td><a th:onclick="'del('+${m.id}+')'">删除</a></td>
        </tr>
        <tfoot>
        <tr>
            <td colspan="7" class="text-center"><a th:href="@{/toShow(page=0)}">首页</a> | <a
                    th:onclick="'first('+ ${pageUtil.page} +')'">&lt;&lt;上一页</a>
                | <a th:onclick="'last('+ ${pageUtil.page} +')'">下一页&gt;&gt;</a> |
                <a th:href="@{/toShow(page=${pageUtil.pageSum}-1)}">尾页</a> 第<span
                        th:text="${pageUtil.page}+1"></span>页/共<span th:text="${pageUtil.pageSum}"></span>页 (<span
                        th:text="${pageUtil.sum}"></span>条)
            </td>
        </tr>
        <tr>
            <td colspan="7" class="text-center"><h5><a href="/add">添加</a></h5></td>
        </tr>
        </tfoot>
    </table>
</div>
</body>
<script th:inline="javascript">
    //获取pageUtil对象
    const pageUtil = /*[[${pageUtil}]]*/{};

    //删除
    function del(num) {
        if (confirm("是否删除")) {
            location.href = "/del?id=" + num;
        }

    }

    //上一页
    function first(num) {
        let i = num - 1;
        if (i < 0) {
            i = 0
        }
        location.href = "/toShow?page=" + i;

    }

    //下一页
    function last(num) {
        let i = num + 1;
        if (i => pageUtil.pageSum) {
            i = pageUtil.pageSum - 1;
        }
        location.href = "/toShow?page=" + i;
    }

</script>

</html>